<template>
  <div>
    <van-nav-bar title="会员信息">
      <img
        src="~assets/image/arrow_left.png"
        width="20"
        height="20"
        slot="left"
        @click="leftClick"
        alt=""
      />
    </van-nav-bar>
    <div class="menberList">
      <p class="menberList-left">姓名</p>
      <p class="menberList-right">{{ username }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">手机</p>
      <p class="menberList-right">{{ phone }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">等级</p>
      <p class="menberList-right">{{ grade }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">地址</p>
      <p class="menberList-right">{{ address }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">团队人数</p>
      <p class="menberList-right">{{ renSum }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">已实名人数</p>
      <p class="menberList-right">{{ realName }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">未实名人数</p>
      <p class="menberList-right">{{ renSum - realName }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">今日收益</p>
      <p class="menberList-right">{{ self }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">当日流水</p>
      <p class="menberList-right">{{ daySelfTrade }}</p>
    </div>
    <div class="menberList">
      <p class="menberList-left">当月流水</p>
      <p class="menberList-right">{{ monthSelfTrade }}</p>
    </div>
  </div>
</template>
<script>
import {
  querySubMemberStatus,
  querySelectTeamRevenueApi,
  querySelectTeamRevenueListApi,
} from "network/ApiServe";
export default {
  Name: "MemberDetailList",
  data() {
    return {
      username: this.$route.params.username,
      phone: this.$route.params.phone,
      grade: this.$route.params.grade,
      address: this.$route.params.address,
      uid: this.$route.params.uid,
      renSum: 0,
      realName: 0,
      data: new Date(),
      self: 0.01,
      daySelfTrade: 0.01,
      monthSelfTrade: 0.01,
    };
  },
  created() {
    this.userId = localStorage.getItem("userId");
    this.token = localStorage.getItem("token");
  },
  mounted() {
    this.getTeamSum();
    this.getSelectTeamRevenue();
    this.getDaySelectTeamRevenue();
    this.getMonthSelectTeamRevenue();
  },
  methods: {
    leftClick() {
      this.$router.back(-1);
    },
    // 团队人数api
    getTeamSum() {
      querySubMemberStatus(this.uid)
        .then((res) => {
          if (res.resp_code == "000000") {
            this.renSum =
              res.result.all.directPush + res.result.all.betweenPush;
            this.realName = res.result.all.realName;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getSelectTeamRevenue() {
      let year = this.data.getFullYear();
      let month = this.data.getMonth() + 1;
      let day = this.data.getDate();
      let riqi = year + "-" + month + "-" + day;

      querySelectTeamRevenueApi(this.uid, riqi, riqi)
        .then((res) => {
          if (res.resp_code == "000000") {
            this.self = res.result.self;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //当日
    getDaySelectTeamRevenue() {
      let year = this.data.getFullYear();
      let month = this.data.getMonth() + 1;
      month = month >= 10 ? month : "0" + mounted;
      let day = this.data.getDate();

      let riqi = year + "-" + month + "-" + day;

      querySelectTeamRevenueListApi(this.uid, riqi, riqi)
        .then((res) => {
          console.log("querySelectTeamRevenueListApi", res);
          if (res.resp_code == "000000") {
            this.daySelfTrade = res.result.selfTrade;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getMonthSelectTeamRevenue() {
      let year = this.data.getFullYear();
      let myear = this.data.getFullYear();

      let month = this.data.getMonth() + 1;
      let mmonth = this.data.getMonth() + 1;
      if (mmonth == 12) {
        mmonth = 1;
        myear += 1;
      } else {
        mmonth += 1;
      }

      month = month >= 10 ? month : "0" + mounted;
      mmonth = mmonth >= 10 ? mmonth : "0" + mounted;

      let day = this.data.getDate();
      let riqi = year + "-" + month + "-01";
      let mriqi = myear + "-" + mmonth + "-01";

      querySelectTeamRevenueListApi(this.uid, riqi, mriqi)
        .then((res) => {
          console.log("querySelectTeamRevenueListApi", res);
          if (res.resp_code == "000000") {
            this.monthSelfTrade = res.result.selfTrade;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style scoped>
.menberList {
  display: flex;
  font-size: 14px;
  background: #fff;
  margin-top: 2px;
  padding: 8px 15px;
  justify-content: space-between;
}
</style>